#ifndef TARGETCOVERAGECHECK_HPP
#define TARGETCOVERAGECHECK_HPP

#include "DataStructures.h"

#include <opencv2/core/core.hpp>

namespace idch {

    /**
      * Checks to see if there is a valid target in both image and that the target has
      * been viewed across enough of the image.
      *
      */
    class TargetCoverageCheck
    {
    public:
        TargetCoverageCheck( int imgWidth , int imgHeight , double desiredCoverage );
        ~TargetCoverageCheck();

        // processes this target location
        // - performs sanity checks to make sure its valid
        // - updates coverage map
        // returns true if the target was accepted as valid
        bool addTarget( const CalibrationLocation &target );

        // has the target been observed across enough of the image
        bool isImageCovered();

        double getCoverage();

        // overlay the coverage map onto the provided RGB image
        void drawCoverage( cv::Mat &img );

        const std::vector<CalibrationLocation>& getTagets();

    private:
        void addToMask( const cv::Point2f &corner );
        bool isTouchingImageEdge( const RectPt &target );
        bool isTargetSimilar( const CalibrationLocation &target );
        void computeRelativeDesc( const RectPt& target , double *angles , double *length );

        double desiredCoverage;

        // list of all the good calibration targets
        std::vector<CalibrationLocation> targets;

        // coverage mask
        cv::Mat mask;
        int totalCoverage;

        int imgWidth;
        int imgHeight;

        double angleTol;
        double distRelTol;
        double edgeTol;

    };

}


#endif // TARGETCOVERAGECHECK_HPP
